<template>
    <div>
      <!-- 如果用用户信息 -->
      <p v-if="$store.state.user.userInfo.name">
        <!-- 用户信息，与积分，头像 -->
        <span>{{ $store.state.user.userInfo.name }}</span>
        <span>积分:{{ $store.state.user.userInfo.score }}</span>
        <img width="120" :src="$store.state.user.userInfo.avatar"/> |
        <!-- 点击退出 -->
        <span @click="logout()">退出</span>
      </p>
      <p v-else>
        <router-link to="/login">登录</router-link> | 
        <router-link to="/register">注册</router-link>
      </p>
        <!-- <p>{{ $store.state.userInfo.name }} |
          积分：{{ $store.state.userInfo.score }} | 
          金币：{{ $store.getters.gold }}
          </p>
        <img :src="$store.state.userInfo.avatar" width="100" v-if="$store.state.userInfo.avatar">
         
          <button @click="$store.commit('ADD_SCORE')">+100</button>
          调用vuex中muations的ADD_SCORE方法 传入参数500
          <button @click="$store.commit('ADD_SCORE',500)">+500</button>
          <br/><hr/>
          <button @click="$store.dispatch('setScore',-50)">等待2秒-50</button>
          <button @click="$store.dispatch('setScore',200)">等待2秒+200</button> -->
          <button @click="$say()">say</button>
          <button @click="$note.show('我爱插件')">调用note插件</button>
    </div>
</template>
<script>
  export default {
    methods:{
      logout(){
        // 给空的用户信息，与token
        this.$store.commit("SET_TOKEN","");
        this.$store.commit("SET_USER",{});
       
      }
    },
    created(){
      this.$request.get("http://dida100.com:8888/api/cart")
      .then(res=>{
        console.log("$request请求的数据",res.data);
      })
    }
  }
</script>